#!/usr/bin/env python3.8
# -*- encoding: utf-8 -*-
'''
@File    :   __init__.py
@Time    :   2022/04/15 15:23:41
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib

from flask import Flask
import click
from flask_migrate import migrate
from app.configs import config
from app.admin import admin_bp
from app.home import home_bp
from app.errors import errors_bp
from app.ext import db,bootstrap,login,moment,csrf,mail,migrate
from app.models import User,UserLog,Tag,Movie,Preview,Comment,MovieCollect,Auth,Role,Admin,AdminLog,OperateLog


def create_app():
    
    app = Flask(__name__)
    # 设置从config中导入设置
    app.config.from_object(config['development'])
    register_blueprints(app)
    register_extensions(app)   
    return app


def register_blueprints(app):
    app.register_blueprint(admin_bp,url_prefix='/admin')
    app.register_blueprint(home_bp)
    app.register_blueprint(errors_bp)

def register_extensions(app):
    db.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    csrf.init_app(app)
    mail.init_app(app)
    login.init_app(app)
    migrate.init_app(app, db)
    
